package main

import (
	"fmt"
	"strconv"
	"os"
	"bufio"
	"io"
	"strings"
)

func convertToBin(n int) string {
	result := ""
	if n==0 {
		result = "0"
	}
	for ; n > 0; n /= 2 {
		lsb := n % 2
		result = strconv.Itoa(lsb) + result
	}

	return result

}

func printFile(filename string)  {
	file ,err := os.Open(filename)
	if err!=nil {
		panic(err)
	}
	printFileContents(file)
	//scanner := bufio.NewScanner(file)
	//for scanner.Scan()  {
	//	fmt.Println(scanner.Text())
	//}
}

func forever()  {
	for   {
		fmt.Println("abc")
	}
}
func main() {

	//fmt.Println(
	//	convertToBin(5),  // 101
	//	convertToBin(13), // 1011 --->1101
	//	convertToBin(121413), // 1011 --->1101
	//	convertToBin(0), // 1011 --->1101
	//)


	printFile("basic/loop/loop.go")
	s := `abc"d"
	k
	k
	123
	p`
	printFileContents(strings.NewReader(s))
	//forever()
}

func printFileContents(read io.Reader)  {
	scanner := bufio.NewScanner(read)
	for scanner.Scan()  {
		fmt.Println(scanner.Text())
	}
	
}
